// modules/test.js
// 引入 Mock
var Mock = require('mockjs')


const dynamicDataSource = {
  url: /\/test\/dynamicDataSource/,
  type: "get",
  response: config => {
    console.log(config.body)
    return {
      errcode: 200,
      result: Mock.mock({
        // 20条数据
        "dynamicData|6": [{
          //id
          "id|+1": 1,
          "name": JSON.parse(config.body).origin + "@id",
          "code": "@uuid",
        }]
      })
    }
  }
}


const selectDataSource = {
  url: /\/test\/selectDataSource/,
  type: "get",
  response: config => {
    console.log(config.body)
    return {
      errcode: 200,
      result: Mock.mock({
        // 20条数据
        "parameter|1-2": [{
          //id
          "id|+1": 1,
          "bindKey": "",
          "type": "",
          "parametKey": /[a-z]{2}[A-Z]{2}/,
          "code": "@uuid",
        }],
        // 20条数据
        "fields|2-5": [{
          //id
          "id|+1": 1,
          "code": /[a-z]{2}[A-Z]{2}/,
          "name": "@cword(2)",
          "fieldKey": '',
        }]
      })
    }
  }
}


const queryDataSource = {
  url: /\/test\/queryDataSource/,
  type: "get",
  response: config => {
    console.log(config.body)
    return {
      errcode: 200,
      result: Mock.mock({
        // 20条数据
        "fields|2-5": [{
          //id
          "id|+1": 1,
          "code": /[a-z]{2}[A-Z]{2}/,
          "name": "@cword(2)",
          "fieldKey": '',
        }]
      })
    }
  }
}


module.exports = [
  dynamicDataSource,
  selectDataSource,
  queryDataSource
]